package com.chushouya.order.constants;


import com.general.framework.core.enums.IEnum;
import com.general.framework.core.exception.Ex;
import com.general.framework.core.lang.Lists;

import java.util.List;
import java.util.Objects;

/**
 * 客服订单操作定义
 */
public enum KefuOrderActionEnum implements IEnum<String> {

    //跟进订单
    FOLLOW("waitOrder", "跟进订单", "跟进订单", Lists.asList(OrderStatusEnum.NEW_ORDER, OrderStatusEnum.WAIT_CHECK,OrderStatusEnum.WAIT_PICKUP, OrderStatusEnum.WAIT_ACCEPT, OrderStatusEnum.WAIT_BARGAIN, OrderStatusEnum.WAIT_VISIT, OrderStatusEnum.WAIT_PAY, OrderStatusEnum.WAIT_CONFIRM, OrderStatusEnum.WAIT_RECEIVE, OrderStatusEnum.WAIT_QUALITY, OrderStatusEnum.WAIT_BARGAIN, OrderStatusEnum.COMPLETE, OrderStatusEnum.CANCELLED,OrderStatusEnum.TIMEOUT,OrderStatusEnum.CLERK_CANCEL,OrderStatusEnum.RETURN_CLOSED,OrderStatusEnum.CLOSED, OrderStatusEnum.CANCELLED, OrderStatusEnum.BACKOUT_CLOSED,OrderStatusEnum.WAIT_RETURN), null, Boolean.FALSE, Lists.asList()),

    SEND_SMS("sendSms", "发送短信", "发送短信", Lists.asList(OrderStatusEnum.NEW_ORDER, OrderStatusEnum.WAIT_CHECK, OrderStatusEnum.WAIT_ACCEPT, OrderStatusEnum.WAIT_BARGAIN, OrderStatusEnum.WAIT_VISIT, OrderStatusEnum.WAIT_PAY, OrderStatusEnum.WAIT_CONFIRM, OrderStatusEnum.WAIT_RECEIVE, OrderStatusEnum.WAIT_QUALITY, OrderStatusEnum.WAIT_BARGAIN, OrderStatusEnum.COMPLETE, OrderStatusEnum.CLOSED, OrderStatusEnum.CANCELLED, OrderStatusEnum.BACKOUT_CLOSED), null, Boolean.TRUE, Lists.asList()),

    ClOSE("closeOrder", "关闭订单", "关闭订单", Lists.asList(OrderStatusEnum.NEW_ORDER,OrderStatusEnum.WAIT_PICKUP, OrderStatusEnum.CANCELLED, OrderStatusEnum.WAIT_CHECK, OrderStatusEnum.WAIT_RECEIVE, OrderStatusEnum.WAIT_BARGAIN, OrderStatusEnum.WAIT_ACCEPT, OrderStatusEnum.WAIT_CONFIRM, OrderStatusEnum.WAIT_VISIT,OrderStatusEnum.WAIT_QUALITY), OrderStatusEnum.CLOSED, Boolean.FALSE, Lists.asList()),

    RECEIVE("orderReceive", "确认收货", "确认收货", Lists.asList(OrderStatusEnum.WAIT_CHECK,OrderStatusEnum.WAIT_PICKUP, OrderStatusEnum.WAIT_RECEIVE), OrderStatusEnum.WAIT_QUALITY, Boolean.TRUE,Lists.asList()),

    RESERVE("orderDeliver", "预约收件", "预约收件", Lists.asList(OrderStatusEnum.NEW_ORDER, OrderStatusEnum.WAIT_PICKUP,OrderStatusEnum.WAIT_CHECK, OrderStatusEnum.WAIT_RECEIVE), OrderStatusEnum.WAIT_RECEIVE, Boolean.TRUE,Lists.asList()),

    DELIVERY("orderDelivery", "确认取件", "确认取件", Lists.asList(OrderStatusEnum.WAIT_CHECK,OrderStatusEnum.WAIT_PICKUP, OrderStatusEnum.WAIT_RECEIVE), OrderStatusEnum.WAIT_RECEIVE, Boolean.TRUE,Lists.asList()),

    RETURN("orderReturn", "操作退货", "操作退货", Lists.asList(OrderStatusEnum.WAIT_BARGAIN, OrderStatusEnum.WAIT_QUALITY,OrderStatusEnum.WAIT_PAY,OrderStatusEnum.WAIT_RETURN), OrderStatusEnum.RETURN_CLOSED, Boolean.TRUE,Lists.asList()),

    QUALITY("orderQuality", "操作质检", "操作质检", Lists.asList(OrderStatusEnum.WAIT_QUALITY), OrderStatusEnum.WAIT_BARGAIN, Boolean.FALSE,Lists.asList()),

    DISPATCH("dispatchOrder", "操作发单", "操作发单", Lists.asList(OrderStatusEnum.NEW_ORDER, OrderStatusEnum.WAIT_CHECK, OrderStatusEnum.WAIT_VISIT, OrderStatusEnum.WAIT_ACCEPT, OrderStatusEnum.WAIT_CONFIRM), OrderStatusEnum.WAIT_ACCEPT, Boolean.TRUE,Lists.asList()),

    BARGAIN("orderBargain", "完成议价", "完成议价", Lists.asList(OrderStatusEnum.WAIT_BARGAIN), OrderStatusEnum.WAIT_PAY, Boolean.FALSE,Lists.asList()),

    REBARGAIN("rollbackToBargain", "重新议价", "重新议价", Lists.asList(OrderStatusEnum.WAIT_PAY), OrderStatusEnum.WAIT_BARGAIN, Boolean.FALSE,Lists.asList()),

    PAY("completePay", "收成打款", "收成打款", Lists.asList(OrderStatusEnum.WAIT_PAY), OrderStatusEnum.COMPLETE, Boolean.TRUE,Lists.asList()),

    COMPLETE("finishOrder", "完成订单", "完成订单", Lists.asList(OrderStatusEnum.WAIT_PAY), OrderStatusEnum.COMPLETE, Boolean.TRUE,Lists.asList()),

    AGAIN("orderAgain", "重新下单", "重新下单", Lists.asList(), OrderStatusEnum.NEW_ORDER, Boolean.FALSE,Lists.asList()),

    RESET("resetOrderStatus", "重置订单", "重置订单", Lists.asList(OrderStatusEnum.CLOSED, OrderStatusEnum.CANCELLED, OrderStatusEnum.CLERK_CANCEL, OrderStatusEnum.BACKOUT_CLOSED,OrderStatusEnum.TIMEOUT, OrderStatusEnum.RETURN_CLOSED), OrderStatusEnum.WAIT_CHECK, Boolean.FALSE,Lists.asList()),

    TIMEOUTCLOSE("timeoutClose", "超时关闭", "超时关闭", Lists.asList(OrderStatusEnum.NEW_ORDER, OrderStatusEnum.WAIT_CHECK, OrderStatusEnum.WAIT_ACCEPT, OrderStatusEnum.WAIT_CONFIRM, OrderStatusEnum.WAIT_VISIT), OrderStatusEnum.TIMEOUT, Boolean.TRUE,Lists.asList()),
    //发送能量

    SENDENERGY("orderSendEnergy", "重发能量", "重发能量", Lists.asList(OrderStatusEnum.COMPLETE), null, Boolean.TRUE,Lists.asList()),
    ;

    private String actionCode;

    /**
     * 操作名称
     */
    private String actionName;

    /**
     * 操作展示名称
     */
    private String actionText;

    /**
     * 执行操作的前置订单状态
     */
    private List<OrderStatusEnum> fromOrderStatus;

    /**
     * 执行操作后的流转订单状态(为空则无状态变更)
     */
    private OrderStatusEnum toOrderStatus;

    /**
     * 额外的条件(初当前订单状态 && 额外条件)
     */
    private Boolean moreCondition;

    private List<String> roles;

    KefuOrderActionEnum(String actionCode, String actionName) {
        this.actionCode = actionCode;
        this.actionName = actionName;
    }

    KefuOrderActionEnum(String actionCode, String actionName, String actionText, List<OrderStatusEnum> fromOrderStatus, OrderStatusEnum toOrderStatus, Boolean moreCondition, List<String> roles) {
        this.actionCode = actionCode;
        this.actionName = actionName;
        this.actionText = actionText;
        this.fromOrderStatus = fromOrderStatus;
        this.toOrderStatus = toOrderStatus;
        this.moreCondition = moreCondition;
        this.roles = roles;
    }

    public static String getDesc(Integer actionCode) {
        for (KefuOrderActionEnum thisEnum : KefuOrderActionEnum.values()) {
            if (Objects.equals(thisEnum.actionCode, actionCode)) {
                return thisEnum.actionName;
            }
        }
        throw Ex.systemError("未定义的客服订单操作[{}]", actionCode);
    }

    public static List<String> getRoles(Integer actionCode) {
        for (KefuOrderActionEnum thisEnum : KefuOrderActionEnum.values()) {
            if (Objects.equals(thisEnum.actionCode, actionCode)) {
                return thisEnum.roles;
            }
        }
        return Lists.emptyList();
    }

    public static String get(Integer actionCode) {
        for (KefuOrderActionEnum thisEnum : KefuOrderActionEnum.values()) {
            if (Objects.equals(thisEnum.actionCode, actionCode)) {
                return thisEnum.actionName;
            }
        }
        throw Ex.systemError("未定义的客服订单操作[{}]", actionCode);
    }

    @Override
    public String value() {
        return this.actionCode;
    }

    @Override
    public String named() {
        return this.actionName;
    }

    public String getActionCode() {
        return actionCode;
    }

    public String getActionName() {
        return actionName;
    }

    public String getActionText() {
        return actionText;
    }

    public List<OrderStatusEnum> fromOrderStatus() {
        return fromOrderStatus;
    }

    public OrderStatusEnum toOrderStatus() {
        return toOrderStatus;
    }

    public Boolean moreCondition() {
        return moreCondition;
    }
}
